package com.mkyong.app;

import java.util.ArrayList;
import java.util.List;

import com.hp.hpl.jena.query.QueryException;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.rdf.model.Model;

public abstract class CustomStore {

	public List<Node> executeQuery(String queryString, Model model) {
		QueryExecution qe = QueryExecutionFactory.create(queryString, model);

		List<Node> nodes = new ArrayList<Node>();

		try {
			com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
			List<String> vars = results.getResultVars();
			while (results.hasNext()) {
				QuerySolution binding = results.nextSolution();
				for (String var : vars) {

					String node = binding.getLiteral(var).getString();
					nodes.add(new Node(var, node));

				}

			}
		} catch (QueryException e) {
			throw new QueryException();
		} finally {
			qe.close();
		}

		return nodes;
	}

	public Model getDefaultModel() {

		return null;
	}

	public abstract void setupStore() throws Exception;
}
